package com.zxl.manager.controller;

import com.google.gson.Gson;
import com.zxl.manager.entity.Comm;
import com.zxl.manager.entity.Order;
import com.zxl.manager.service.CommService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jimmy on 2017/7/16.
 */
@Controller
public class CommController {
    @Autowired
    private CommService commService;

    private Gson gson = new Gson();

    @RequestMapping("/commIdx")
    public ModelAndView commIdx(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("commission/index");
        return mv;
    }


    @RequestMapping("/getAllComm")
    @ResponseBody
    public String getAllComm(Integer limit,Integer offset){
        Map<String, Object> resMap = new HashMap<>();
        List<Comm> list = commService.getAllConn(limit,offset);
        int total = commService.getCommCnt();
        resMap.put("total",total);
        resMap.put("rows",list);
        String res = gson.toJson(resMap);
        return res;
    }

    @RequestMapping("/getLevels")
    @ResponseBody
    public String getLevels(){
        List<Map<String,String>> levels = commService.getLevels();
        return gson.toJson(levels);
    }

    @RequestMapping("/updComm")
    @ResponseBody
    public String updComm(String level1,String level2){
        Map<String,String> resMap = new HashMap<>();
        commService.updComm(level1, level2);
        resMap.put("code","0");
        return gson.toJson(resMap);
    }
}
